
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The impact of divorce laws on the equilibrium in the marriage market.
% Reynoso
% April 2024
%
% This file inputs estimates and produces moments and utilities under the
% mutual consent regime.
%  
% Data: PSID 1968-1992
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------------ Replication Path -------------------------------%

clc
clear all

%--- Indicate location of Replication folder:
%replication_location = 'C:\update_with_your_path';

%------------------------ Preliminaries ----------------------------------%

%--- Path for Model
addpath(genpath([replication_location,'\Internal_estimation\Inputs']));

%--- Path for estimates
estimates_dir = [replication_location,'\Outputs\MCD\'];

%--- Path for storing
output_dir = [replication_location,'\Outputs'];

%------------------------ Targeted moments -------------------------------%

%--- Moments and utilities
load([estimates_dir, 'outputs_mcd']);
params=X;
[F, model_moments_mc, moment_cond, U_mc_bymkt, U_mc_tot_bymkt] = moments(n_g, T, lt, dt, H_max, disc, stoch_earn_f, stoch_earn_m, m_eta_f, m_eta_m, n_eta_f, n_eta_m, home_prod, match_qual, m_th, n_th, gamma, L_max, params, data_moments, data_f, data_m, W);

%--- Save
save(fullfile(output_dir,'\MCD\U_mc'),'U_mc_bymkt','U_mc_tot_bymkt'); 
save(fullfile(output_dir,'\MCD\moments_mc'),'model_moments_mc');

%------------------------ Unargeted moments ------------------------------%

model_moments_bymkt = reshape(model_moments_mc(1:168), 168/4,4); 
women_model_moments_bymkt = model_moments_bymkt(1:9,:)./data_f;

[duration, duration_nbr, divorcees_nbr, model_sahw_t]=moments_postestimation(n_g, T, lt, dt, H_max, disc, stoch_earn_f, stoch_earn_m, m_eta_f, m_eta_m, n_eta_f, n_eta_m, home_prod, match_qual, m_th, n_th, gamma, L_max, params, data_moments, data_f, data_m, W);

%--- Duration
duration_all = duration(:,1)*0.23 + duration(:,2)*0.23 + duration(:,3)*0.36 + duration(:,4)*0.18;

%--- Fraction wives staying at home
sahw_hs_bymk = sum(model_sahw_t(1:3,:,:).*women_model_moments_bymkt(1:3,1));
sahw_sc_bymk = sum(model_sahw_t(4:6,:,:).*women_model_moments_bymkt(4:6,1));
sahw_cp_bymk = sum(model_sahw_t(7:9,:,:).*women_model_moments_bymkt(7:9,1));
model_sahw_t_byeduct = [sahw_hs_bymk(:,:,1)*0.23 + sahw_hs_bymk(:,:,2)*0.23 + sahw_hs_bymk(:,:,3)*0.36 + sahw_hs_bymk(:,:,4)*0.18;...
                        sahw_sc_bymk(:,:,1)*0.23 + sahw_sc_bymk(:,:,2)*0.23 + sahw_sc_bymk(:,:,3)*0.36 + sahw_sc_bymk(:,:,4)*0.18;...
                        sahw_cp_bymk(:,:,1)*0.23 + sahw_cp_bymk(:,:,2)*0.23 + sahw_cp_bymk(:,:,3)*0.36 + sahw_cp_bymk(:,:,4)*0.18];

%--- Save
save(fullfile(output_dir,'\MCD\moments_mc_untargeted'),'model_sahw_t_byeduct','duration_all');












